/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: FieldUtils.java   2020-09-28 21-49-29
 * Author: Evan
 */
package cn.datacare.orm.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * Title: 类字段工具类
 * </p>
 * <p>
 * Description: 类字段工具类
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-09-28 21-49-29
 * @since V1.0
 */
public class FieldUtils {
    /***
     * java.lang.object:{@value}
     */
    public static final String JAVA_LANG_OBJECT="java.lang.object";

    /**
     * 获取期个类所有字段 包括父类的字段
     * @param clazz Class
     * @return List<Field> 字段列表
     */
    public static List<Field> getAllFields(Class clazz){
        List<Field> fieldList = new ArrayList<>() ;

        while (clazz != null && !JAVA_LANG_OBJECT.equals(clazz.getName().toLowerCase())) {
            fieldList.addAll(Arrays.asList(clazz .getDeclaredFields()));
            clazz = clazz.getSuperclass();
        }
        return fieldList;
    }
}
